/*
 * Copyright (c) 2013-2018 上海汇数数据. All rights reserved.
 * @(#) TripleDesCipherApi.java 2018-08-06 17:26
 */

package cn.jh.common.core.crypto;

import org.jetbrains.annotations.Nullable;

import java.security.Key;


/**
 * 基于JCA体系的 `CipherApi` 接口的 `DESede` 加密算法的实现。
 *
 * @author Fuchun
 * @since 1.0
 */
public class TripleDesCipherApi extends BlockCipherApi {

    private static final String ALGORITHM = "DESede";

    private static final TripleDesCipherApi DEFAULT_API = new TripleDesCipherApi(CipherParamsKt
            .DEFAULT_TRIPLE_DES_PARAMS);

    /**
     * 返回默认的{@code TripleDesCipherApi}。
     * <pre>
     * 1. transformation: "DESede/ECB/PKCS5Padding"
     * 2. key size: 168
     * 3. default secureRandom
     * </pre>
     */
    public static TripleDesCipherApi getInstance() {
        return DEFAULT_API;
    }

    private TripleDesCipherApi(SymmetricCipherParams params) {
        super(params);
    }

    @Override
    protected byte[] encrypt(byte[] plaintext, byte[] key, @Nullable byte[] iv) {
        return super.encrypt(plaintext, key, null);
    }

    @Override
    protected byte[] decrypt(byte[] cipherText, byte[] key, @Nullable byte[] parameters) {
        return super.decrypt(cipherText, key, null);
    }

    @Override
    protected byte[] encrypt(byte[] plaintext, Key key, @Nullable byte[] iv) {
        return super.encrypt(plaintext, key, null);
    }

    @Override
    protected byte[] decrypt(byte[] cipherText, Key key, @Nullable byte[] parameters) {
        return super.decrypt(cipherText, key, null);
    }
}
